package com.aloda.ojcommon.domain.enums;

import cn.hutool.core.util.ObjectUtil;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author aloda
 * @Date 2025/4/22 16:29
 */
public enum UserRoleEnum {
    ADMIN("admin", "管理员"),
    USER("user", "普通用户");

    private final String role;

    private final String value;

    UserRoleEnum(String role, String value) {
        this.role = role;
        this.value = value;
    }

    /**
     * 根据 value 获取枚举
     *
     * @param role
     * @return
     */
    public static UserRoleEnum getEnumByRole(String role) {
        if (ObjectUtil.isEmpty(role)) {
            return null;
        }
        for (UserRoleEnum anEnum : UserRoleEnum.values()) {
            if (anEnum.role.equals(role)) {
                return anEnum;
            }
        }
        return null;
    }

    /**
     * 获取值列表
     *
     * @return
     */
    public static List<String> getValues() {
        return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList());
    }

    public String getValue() {
        return value;
    }

    public String getRole() {
        return role;
    }
}
